<?php

namespace app\admin\model\project;

use think\Model;


class Project extends Model
{

    

    

    // 表名
    protected $name = 'project';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
//    protected $append = [
//        'project_priority_text',
//        'status_text'
//    ];
//

    
    public function getProjectPriorityList()
    {
        return ['1' => __('Project_priority 1'), '2' => __('Project_priority 2')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
    }


    public function getProjectPriorityTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['project_priority']) ? $data['project_priority'] : '');
        $list = $this->getProjectPriorityList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function subject()
    {
        return $this->belongsTo('app\admin\model\Subject', 'subject_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function type()
    {
        return $this->belongsTo('app\admin\model\Type', 'type_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
